
package com.wwy.monitor.util;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import com.alibaba.buc.sso.client.vo.BucSSOUser;
import com.alibaba.dt.onelog.OneLog;
import com.alibaba.oplog.pub.collector.client.enums.ClientTypeEunm;
import com.alibaba.oplog.pub.collector.client.enums.OPLevel;
import com.alibaba.oplog.pub.collector.client.model.ClientIdModel;
import com.autonavi.acis.system.model.User;

/**
 * @Descriptionï¼
 * @Author: zhenfei.gz
 * @Date: 2020/8/4 8:24 PM
 */
public class OneLogUtil {
    /**
     * @param request åå«ç¨æ·ä¿¡æ¯
     * @param url     è®¿é®çurl
     * @param urlName
     */
    public static void getOpLog(String url, String urlName, HttpServletRequest request) {
        BucSSOUser user = null;
        try {
            user = UserUtils.getUser(request);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ServletException e) {
            e.printStackTrace();
        }
        if (user != null) {
            OneLog.getOpLog()  //è·åæ¥å¿å·¥å·
                    .logBucUserId(
//*å¿å¡«*è®°å½bucç¨æ·idï¼æ³¨æåå·¥å·¥å·empIdåbucIdçåºå«ï¼æ bucå¯å¨extInfoå­æ®µå¤æ³¨å¶ä»ç±»åï¼
                            String.valueOf(user.getId()))
//æµç§°ï¼ä¸è¬å¡«æä½äººè±å
                    .logOperatorNick(user.getNickNameCn())
//å§åï¼ä¸è¬å¡«åæä½äººçå®åå­
                    .logOperatorName(user.getLastName())
//ä¸å¡ç±»å:æ¥è¯¢(query)/æ´æ°(update)/å é¤(delete)/etc
                    .logOpType("æ¥è¯¢")
//å®¢æ·ID:å¦å®¢æ·ID/æ¥è®¿URL/é¡µé¢Path/etc
                    .logCustomerId(url)
//*å¿å¡«* ä¸å¡æä½:å¦äº§åè°ä»·/æ¥è¯¢**/ç­ç¥æ´æ°/**æäº¤/**åå¸/**åæ´
                    .logOpName(urlName)
// *å¿å¡«* æä½è¡ä¸ºå®å¨ç­çº§
                    .logOpLogLevel(OPLevel.NORMAL.getDesc())
// *å¿å¡«* ä¸å¡å¯¹è±¡åç§°:å¦æ¥è¡¨åç§°/ç±»ç®åç§°/èååç§°/æéåç§°/ç¨æ·åç§°/etc
                    .logOpItem(urlName)
// *å¿å¡«* ä¸å¡å¯¹è±¡ç¼å·:å¦æ¥è¡¨ID/ç±»ç®ID/èåID/æéID/ç¨æ·ID/etc
                    .logOpItemId(urlName)
// *å¿å¡«* å®¢æ·ç«¯æ è¯(å»ºè®®å¡«å¥bucçumidï¼æ bucå¯éå®¢æ·ç«¯IP)
                    .logClientId(new ClientIdModel(ClientTypeEunm.UMID, user.getEmpId(), request))
//ä¸å¡æä½ä¿¡æ¯:å¦æä½ä¸ä¸æ参数(å»ºè®®JSON)
                    .logOpContent("{}")
//æä½æè¿°:å¦è¿åå¼/etc(å»ºè®®JSON)
                    .logOpDesc("{}")
//è¥bucUserIdå¡«åå¼ébucç¨æ·idï¼èæ¯åå·¥å·¥å·emp_id(å·¥å·åä¸è¦è¡¥0)ï¼è¯·å¨æ­¤å¤åºå®å¡«åï¼USER_TYPE_EMPIDï¼å¶ä»è´¦å·ä½ç³»å¡«åï¼USER_TYPE_OTHER
                    .logExtInfo("")
                    .log();
        }
    }
}